import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { map, Observable } from 'rxjs';

interface Data<T>{
  data:T,
}
@Injectable()
export class ResponseInterceptor<T> implements NestInterceptor{
  intercept(context: ExecutionContext, next: CallHandler): Observable<Data<T>> | Promise<Observable<any>> {
    return next.handle().pipe(map(data => {
      return {
        data,
        status: 0,
        message: "success",
        success: true
      }
    }));
  }
}